/**
 * 
 */
package de.gee.erep.shared.entities.citizen;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author Matthew Gee created: 07.05.2011
 */
public class Citizen implements Serializable, Comparable<Citizen> {
	/***/
	private static final long serialVersionUID = 1L;
	/***/
	public static String[] fieldnames = { "name", "id", "avatar-link",
			"date-of-birth", "is-president", "is-congressman",
			"is-organization", "is-general-manager" };
	public ArrayList<CitizenDetailId> detailIds = new ArrayList<CitizenDetailId>();

	public Citizen() {
	}

	public Citizen(String name, int citizenId, String avatar) {
		this.name = name;
		this.citizenId = citizenId;
		this.avatarLink = avatar;
	}

	private String name;
	private int citizenId;
	private String avatarLink;
	private String dateOfbirth;
	private String link;

	private boolean isPresident;
	private boolean isCongressMan;
	private boolean isGeneralManger;
	private boolean isOrganization;

	/**
	 * @param element
	 * @param data
	 */
	public void set(String element, String data) {
		try {
			if (element.equals(fieldnames[0])) {
				name = data;
			} else if (element.equals(fieldnames[1])) {
				citizenId = Integer.valueOf(data);
				link = "http://www.erepublik.com/de/citizen/profile/"
						+ citizenId;
			} else if (element.equals(fieldnames[2])) {
				avatarLink = data;
			} else if (element.equals(fieldnames[3])) {
				dateOfbirth = data;
			} else if (element.equals(fieldnames[4])) {
				isPresident = Boolean.valueOf(data);
			} else if (element.equals(fieldnames[5])) {
				isOrganization = Boolean.valueOf(data);
			} else if (element.equals(fieldnames[6])) {
				isCongressMan = Boolean.valueOf(data);
			} else if (element.equals(fieldnames[7])) {
				isGeneralManger = Boolean.valueOf(data);
			}
		} catch (NumberFormatException e) {
			System.err.println("idNotSet");
		}
	}

	/**
	 * @param id
	 */
	public void add(CitizenDetailId id) {
		detailIds.add(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Citizen: " + name + ", avatar: " + !avatarLink.isEmpty()
				+ ", Details: " + detailIds.size();
	}

	/**
	 * @return the detailIds
	 */
	public ArrayList<CitizenDetailId> getDetailIds() {
		return detailIds;
	}

	/**
	 * @return the citizenId
	 */
	public int getCitizenId() {
		return citizenId;
	}

	/**
	 * @return the avatarLink
	 */
	public String getAvatarLink() {
		return avatarLink;
	}

	/**
	 * @return the dateOfbirth
	 */
	public String getDateOfbirth() {
		return dateOfbirth;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(final Citizen c) {
		return Integer.valueOf(this.citizenId).compareTo(c.citizenId);
	}
}
